<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/7/19
 * Time: 16:04
 */
namespace Publish\Controller;
use Common\Controller\HomebaseController;
session_start();
class SecondController extends HomebaseController
{
    protected $terms_model;
   	protected $image_model;
   	protected $person_model;

    function _initialize() {
        parent::_initialize();
        $this->terms_model = D("Publish/SystemTerms");
        $this->image_model = D("Publish/PubImage");
        $this->person_model = D('Publish/PubPerson');
    }
    public function index(){
    	$id=I('id');
    	$second_data=$this->terms_model
    		 ->where("term_id=$id")
    		 ->find();

    	$parent=$second_data['parent'];
    	$first_data=$this->terms_model
             ->where("parent=$parent")
             ->select();
	// 查询二级分类底下的人物
    	$data=$this->person_model
			->alias("p")
			->join("__SYSTEM_TERM_RELATIONSHIPS__ as b on b.object_id =p.id")
			->field('p.id,p.name')
			->where(array("b.term_id"=>$id))
			->order("p.listorder desc,p.id asc")
			->select();
		for($i=0;$i<count($data);$i++){
			$imgs=$this->image_model
				->where(array("person_id"=>$data[$i]['id'],"img_mark"=>0))
				->find();
			$data[$i]['img_url']=$imgs['img_url'];
		}
		// echo json_encode($data);
    		 // dump($data);
		$this->assign("first_data",$first_data);
		$this->assign("second_person",$data);
    	$this->assign("second_data",$second_data);
		$this->display("second_m");
		}
}